Removed CVS keywords from files, to make merging between branches
[lhc/web/wiklou.git] / includes / OutputPage.php
1 <?php
2 /**
3 * @package MediaWiki
4 */
5
6 /**
7 * This is not a valid entry point, perform no further processing unless MEDIAWIKI is defined
8 */
9 if( defined( 'MEDIAWIKI' ) ) {
10
11 # See design.doc
12
13 if($wgUseTeX) require_once( 'Math.php' );
14
15 /**
16 * @todo document
17 * @package MediaWiki
18 */
19 class OutputPage {
20 var $mHeaders, $mCookies, $mMetatags, $mKeywords;
21 var $mLinktags, $mPagetitle, $mBodytext, $mDebugtext;
22 var $mHTMLtitle, $mRobotpolicy, $mIsarticle, $mPrintable;
23 var $mSubtitle, $mRedirect;
24 var $mLastModified, $mCategoryLinks;
25 var $mScripts, $mLinkColours;
26
27 var $mSuppressQuickbar;
28 var $mOnloadHandler;
29 var $mDoNothing;
30 var $mContainsOldMagic, $mContainsNewMagic;
31 var $mIsArticleRelated;
32 var $mParserOptions;
33 var $mShowFeedLinks = false;
34 var $mEnableClientCache = true;
35
36 /**
37 * Constructor
38 * Initialise private variables
39 */
40 function OutputPage() {
41 $this->mHeaders = $this->mCookies = $this->mMetatags =
42 $this->mKeywords = $this->mLinktags = array();
43 $this->mHTMLtitle = $this->mPagetitle = $this->mBodytext =
44 $this->mRedirect = $this->mLastModified =
45 $this->mSubtitle = $this->mDebugtext = $this->mRobotpolicy =
46 $this->mOnloadHandler = '';
47 $this->mIsArticleRelated = $this->mIsarticle = $this->mPrintable = true;
48 $this->mSuppressQuickbar = $this->mPrintable = false;
49 $this->mLanguageLinks = array();
50 $this->mCategoryLinks = array() ;
51 $this->mDoNothing = false;
52 $this->mContainsOldMagic = $this->mContainsNewMagic = 0;
53 $this->mParserOptions = ParserOptions::newFromUser( $temp = NULL );
54 $this->mSquidMaxage = 0;
55 $this->mScripts = '';
56 }
57
58 function addHeader( $name, $val ) { array_push( $this->mHeaders, $name.': '.$val ) ; }
59 function addCookie( $name, $val ) { array_push( $this->mCookies, array( $name, $val ) ); }
60 function redirect( $url, $responsecode = '302' ) { $this->mRedirect = $url; $this->mRedirectCode = $responsecode; }
61
62 # To add an http-equiv meta tag, precede the name with "http:"
63 function addMeta( $name, $val ) { array_push( $this->mMetatags, array( $name, $val ) ); }
64 function addKeyword( $text ) { array_push( $this->mKeywords, $text ); }
65 function addScript( $script ) { $this->mScripts .= $script; }
66 function getScript() { return $this->mScripts; }
67
68 function addLink( $linkarr ) {
69 # $linkarr should be an associative array of attributes. We'll escape on output.
70 array_push( $this->mLinktags, $linkarr );
71 }
72
73 function addMetadataLink( $linkarr ) {
74 # note: buggy CC software only reads first "meta" link
75 static $haveMeta = false;
76 $linkarr['rel'] = ($haveMeta) ? 'alternate meta' : 'meta';
77 $this->addLink( $linkarr );
78 $haveMeta = true;
79 }
80
81 /**
82 * checkLastModified tells the client to use the client-cached page if
83 * possible. If sucessful, the OutputPage is disabled so that
84 * any future call to OutputPage->output() have no effect. The method
85 * returns true iff cache-ok headers was sent.
86 */
87 function checkLastModified ( $timestamp ) {
88 global $wgLang, $wgCachePages, $wgUser;
89 $timestamp=wfTimestamp(TS_MW,$timestamp);
90 if( !$wgCachePages ) {
91 wfDebug( "CACHE DISABLED\n", false );
92 return;
93 }
94 if( preg_match( '/MSIE ([1-4]|5\.0)/', $_SERVER["HTTP_USER_AGENT"] ) ) {
95 # IE 5.0 has probs with our caching
96 wfDebug( "-- bad client, not caching\n", false );
97 return;
98 }
99 if( $wgUser->getOption( 'nocache' ) ) {
100 wfDebug( "USER DISABLED CACHE\n", false );
101 return;
102 }
103
104 $lastmod = gmdate( 'D, j M Y H:i:s', wfTimestamp(TS_UNIX, max( $timestamp, $wgUser->mTouched ) ) ) . ' GMT';
105
106 if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
107 # IE sends sizes after the date like this:
108 # Wed, 20 Aug 2003 06:51:19 GMT; length=5202
109 # this breaks strtotime().
110 $modsince = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
111 $ismodsince = wfTimestamp( TS_MW, strtotime( $modsince ) );
112 wfDebug( "-- client send If-Modified-Since: " . $modsince . "\n", false );
113 wfDebug( "-- we might send Last-Modified : $lastmod\n", false );
114 if( ($ismodsince >= $timestamp ) and $wgUser->validateCache( $ismodsince ) ) {
115 # Make sure you're in a place you can leave when you call us!
116 header( "HTTP/1.0 304 Not Modified" );
117 $this->mLastModified = $lastmod;
118 $this->sendCacheControl();
119 wfDebug( "CACHED client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
120 $this->disable();
121 return true;
122 } else {
123 wfDebug( "READY client: $ismodsince ; user: $wgUser->mTouched ; page: $timestamp\n", false );
124 $this->mLastModified = $lastmod;
125 }
126 } else {
127 wfDebug( "We're confused.\n", false );
128 $this->mLastModified = $lastmod;
129 }
130 }
131
132 function getPageTitleActionText () {
133 global $action;
134 switch($action) {
135 case 'edit':
136 return wfMsg('edit');
137 case 'history':
138 return wfMsg('history_short');
139 case 'protect':
140 return wfMsg('protect');
141 case 'unprotect':
142 return wfMsg('unprotect');
143 case 'delete':
144 return wfMsg('delete');
145 case 'watch':
146 return wfMsg('watch');
147 case 'unwatch':
148 return wfMsg('unwatch');
149 case 'submit':
150 return wfMsg('preview');
151 case 'info':
152 return wfMsg('info_short');
153 default:
154 return '';
155 }
156 }
157
158 function setRobotpolicy( $str ) { $this->mRobotpolicy = $str; }
159 function setHTMLTitle( $name ) {$this->mHTMLtitle = $name; }
160 function setPageTitle( $name ) {
161 global $action, $wgContLang;
162 $name = $wgContLang->convert($name, true);
163 $this->mPagetitle = $name;
164 if(!empty($action)) {
165 $taction = $this->getPageTitleActionText();
166 if( !empty( $taction ) ) {
167 $name .= ' - '.$taction;
168 }
169 }
170 $this->setHTMLTitle( $name . ' - ' . wfMsg( 'wikititlesuffix' ) );
171 }
172 function getHTMLTitle() { return $this->mHTMLtitle; }
173 function getPageTitle() { return $this->mPagetitle; }
174 function setSubtitle( $str ) { $this->mSubtitle = $str; }
175 function getSubtitle() { return $this->mSubtitle; }
176 function isArticle() { return $this->mIsarticle; }
177 function setPrintable() { $this->mPrintable = true; }
178 function isPrintable() { return $this->mPrintable; }
179 function setSyndicated( $show = true ) { $this->mShowFeedLinks = $show; }
180 function isSyndicated() { return $this->mShowFeedLinks; }
181 function setOnloadHandler( $js ) { $this->mOnloadHandler = $js; }
182 function getOnloadHandler() { return $this->mOnloadHandler; }
183 function disable() { $this->mDoNothing = true; }
184
185 function setArticleRelated( $v ) {
186 $this->mIsArticleRelated = $v;
187 if ( !$v ) {
188 $this->mIsarticle = false;
189 }
190 }
191 function setArticleFlag( $v ) {
192 $this->mIsarticle = $v;
193 if ( $v ) {
194 $this->mIsArticleRelated = $v;
195 }
196 }
197
198 function isArticleRelated() { return $this->mIsArticleRelated; }
199
200 function getLanguageLinks() { return $this->mLanguageLinks; }
201 function addLanguageLinks($newLinkArray) {
202 $this->mLanguageLinks += $newLinkArray;
203 }
204 function setLanguageLinks($newLinkArray) {
205 $this->mLanguageLinks = $newLinkArray;
206 }
207
208 function getCategoryLinks() {
209 return $this->mCategoryLinks;
210 }
211 function addCategoryLinks($newLinkArray) {
212 $this->mCategoryLinks += $newLinkArray;
213 }
214 function setCategoryLinks($newLinkArray) {
215 $this->mCategoryLinks += $newLinkArray;
216 }
217
218 function suppressQuickbar() { $this->mSuppressQuickbar = true; }
219 function isQuickbarSuppressed() { return $this->mSuppressQuickbar; }
220
221 function addHTML( $text ) { $this->mBodytext .= $text; }
222 function clearHTML() { $this->mBodytext = ''; }
223 function debug( $text ) { $this->mDebugtext .= $text; }
224
225 function setParserOptions( $options ) {
226 return wfSetVar( $this->mParserOptions, $options );
227 }
228
229 /**
230 * Convert wikitext to HTML and add it to the buffer
231 */
232 function addWikiText( $text, $linestart = true ) {
233 global $wgParser, $wgTitle, $wgUseTidy;
234
235 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions, $linestart );
236 $this->mLanguageLinks += $parserOutput->getLanguageLinks();
237 $this->mCategoryLinks += $parserOutput->getCategoryLinks();
238 $this->addHTML( $parserOutput->getText() );
239 }
240
241 /**
242 * Add wikitext to the buffer, assuming that this is the primary text for a page view
243 * Saves the text into the parser cache if possible
244 */
245 function addPrimaryWikiText( $text, $cacheArticle ) {
246 global $wgParser, $wgParserCache, $wgUser, $wgTitle, $wgUseTidy;
247
248 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions, true );
249
250 $text = $parserOutput->getText();
251
252 if ( $cacheArticle ) {
253 $wgParserCache->save( $parserOutput, $cacheArticle, $wgUser );
254 }
255
256 $this->mLanguageLinks += $parserOutput->getLanguageLinks();
257 $this->mCategoryLinks += $parserOutput->getCategoryLinks();
258 $this->addHTML( $text );
259 }
260
261 /**
262 * Add the output of a QuickTemplate to the output buffer
263 * @param QuickTemplate $template
264 */
265 function addTemplate( &$template ) {
266 ob_start();
267 $template->execute();
268 $this->addHtml( ob_get_contents() );
269 ob_end_clean();
270 }
271
272 /**
273 * Parse wikitext and return the HTML. This is for special pages that add the text later
274 */
275 function parse( $text, $linestart = true ) {
276 global $wgParser, $wgTitle;
277 $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions, $linestart );
278 return $parserOutput->getText();
279 }
280
281 /**
282 * @param $article
283 * @param $user
284 */
285 function tryParserCache( $article, $user ) {
286 global $wgParserCache;
287 $parserOutput = $wgParserCache->get( $article, $user );
288 if ( $parserOutput !== false ) {
289 $this->mLanguageLinks += $parserOutput->getLanguageLinks();
290 $this->mCategoryLinks += $parserOutput->getCategoryLinks();
291 $this->addHTML( $parserOutput->getText() );
292 return true;
293 } else {
294 return false;
295 }
296 }
297
298 /**
299 * Set the maximum cache time on the Squid in seconds
300 * @param $maxage
301 */
302 function setSquidMaxage( $maxage ) {
303 $this->mSquidMaxage = $maxage;
304 }
305
306 /**
307 * Use enableClientCache(false) to force it to send nocache headers
308 * @param $state
309 */
310 function enableClientCache( $state ) {
311 return wfSetVar( $this->mEnableClientCache, $state );
312 }
313
314 function sendCacheControl() {
315 global $wgUseSquid, $wgUseESI;
316 # FIXME: This header may cause trouble with some versions of Internet Explorer
317 header( 'Vary: Accept-Encoding, Cookie' );
318 if( $this->mEnableClientCache ) {
319 if( $wgUseSquid && ! isset( $_COOKIE[ini_get( 'session.name') ] ) &&
320 ! $this->isPrintable() && $this->mSquidMaxage != 0 )
321 {
322 if ( $wgUseESI ) {
323 # We'll purge the proxy cache explicitly, but require end user agents
324 # to revalidate against the proxy on each visit.
325 # Surrogate-Control controls our Squid, Cache-Control downstream caches
326 wfDebug( "** proxy caching with ESI; {$this->mLastModified} **\n", false );
327 # start with a shorter timeout for initial testing
328 # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"');
329 header( 'Surrogate-Control: max-age='.$wgSquidMaxage.'+'.$this->mSquidMaxage.', content="ESI/1.0"');
330 header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' );
331 } else {
332 # We'll purge the proxy cache for anons explicitly, but require end user agents
333 # to revalidate against the proxy on each visit.
334 # IMPORTANT! The Squid needs to replace the Cache-Control header with
335 # Cache-Control: s-maxage=0, must-revalidate, max-age=0
336 wfDebug( "** local proxy caching; {$this->mLastModified} **\n", false );
337 # start with a shorter timeout for initial testing
338 # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" );
339 header( 'Cache-Control: s-maxage='.$this->mSquidMaxage.', must-revalidate, max-age=0' );
340 }
341 } else {
342 # We do want clients to cache if they can, but they *must* check for updates
343 # on revisiting the page.
344 wfDebug( "** private caching; {$this->mLastModified} **\n", false );
345 header( "Expires: -1" );
346 header( "Cache-Control: private, must-revalidate, max-age=0" );
347 }
348 if($this->mLastModified) header( "Last-modified: {$this->mLastModified}" );
349 } else {
350 wfDebug( "** no caching **\n", false );
351
352 # In general, the absence of a last modified header should be enough to prevent
353 # the client from using its cache. We send a few other things just to make sure.
354 header( 'Expires: -1' );
355 header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' );
356 header( 'Pragma: no-cache' );
357 }
358 }
359
360 /**
361 * Finally, all the text has been munged and accumulated into
362 * the object, let's actually output it:
363 */
364 function output() {
365 global $wgUser, $wgLang, $wgDebugComments, $wgCookieExpiration;
366 global $wgInputEncoding, $wgOutputEncoding, $wgContLanguageCode;
367 global $wgDebugRedirects, $wgMimeType, $wgProfiler;
368
369 if( $this->mDoNothing ){
370 return;
371 }
372 $fname = 'OutputPage::output';
373 wfProfileIn( $fname );
374 $sk = $wgUser->getSkin();
375
376 if ( '' != $this->mRedirect ) {
377 if( substr( $this->mRedirect, 0, 4 ) != 'http' ) {
378 # Standards require redirect URLs to be absolute
379 global $wgServer;
380 $this->mRedirect = $wgServer . $this->mRedirect;
381 }
382 if( $this->mRedirectCode == '301') {
383 if( !$wgDebugRedirects ) {
384 header("HTTP/1.1 {$this->mRedirectCode} Moved Permanently");
385 }
386 $this->mLastModified = gmdate( 'D, j M Y H:i:s' ) . ' GMT';
387 }
388
389 $this->sendCacheControl();
390
391 if( $wgDebugRedirects ) {
392 $url = htmlspecialchars( $this->mRedirect );
393 print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
394 print "<p>Location: <a href=\"$url\">$url</a></p>\n";
395 print "</body>\n</html>\n";
396 } else {
397 header( 'Location: '.$this->mRedirect );
398 }
399 if ( isset( $wgProfiler ) ) { wfDebug( $wgProfiler->getOutput() ); }
400 return;
401 }
402
403
404 # Buffer output; final headers may depend on later processing
405 ob_start();
406
407 $this->transformBuffer();
408
409 # Disable temporary placeholders, so that the skin produces HTML
410 $sk->postParseLinkColour( false );
411
412 header( "Content-type: $wgMimeType; charset={$wgOutputEncoding}" );
413 header( 'Content-language: '.$wgContLanguageCode );
414
415 $exp = time() + $wgCookieExpiration;
416 foreach( $this->mCookies as $name => $val ) {
417 setcookie( $name, $val, $exp, '/' );
418 }
419
420 wfProfileIn( 'Output-skin' );
421 $sk->outputPage( $this );
422 wfProfileOut( 'Output-skin' );
423
424 $this->sendCacheControl();
425 ob_end_flush();
426 }
427
428 function out( $ins ) {
429 global $wgInputEncoding, $wgOutputEncoding, $wgContLang;
430 if ( 0 == strcmp( $wgInputEncoding, $wgOutputEncoding ) ) {
431 $outs = $ins;
432 } else {
433 $outs = $wgContLang->iconv( $wgInputEncoding, $wgOutputEncoding, $ins );
434 if ( false === $outs ) { $outs = $ins; }
435 }
436 print $outs;
437 }
438
439 function setEncodings() {
440 global $wgInputEncoding, $wgOutputEncoding;
441 global $wgUser, $wgContLang;
442
443 $wgInputEncoding = strtolower( $wgInputEncoding );
444
445 if( $wgUser->getOption( 'altencoding' ) ) {
446 $wgContLang->setAltEncoding();
447 return;
448 }
449
450 if ( empty( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
451 $wgOutputEncoding = strtolower( $wgOutputEncoding );
452 return;
453 }
454
455 /*
456 # This code is unused anyway!
457 # Commenting out. --bv 2003-11-15
458
459 $a = explode( ",", $_SERVER['HTTP_ACCEPT_CHARSET'] );
460 $best = 0.0;
461 $bestset = "*";
462
463 foreach ( $a as $s ) {
464 if ( preg_match( "/(.*);q=(.*)/", $s, $m ) ) {
465 $set = $m[1];
466 $q = (float)($m[2]);
467 } else {
468 $set = $s;
469 $q = 1.0;
470 }
471 if ( $q > $best ) {
472 $bestset = $set;
473 $best = $q;
474 }
475 }
476 #if ( "*" == $bestset ) { $bestset = "iso-8859-1"; }
477 if ( "*" == $bestset ) { $bestset = $wgOutputEncoding; }
478 $wgOutputEncoding = strtolower( $bestset );
479
480 # Disable for now
481 #
482 */
483 $wgOutputEncoding = $wgInputEncoding;
484 }
485
486 /**
487 * Returns a HTML comment with the elapsed time since request.
488 * This method has no side effects.
489 */
490 function reportTime() {
491 global $wgRequestTime;
492
493 $now = wfTime();
494 list( $usec, $sec ) = explode( ' ', $wgRequestTime );
495 $start = (float)$sec + (float)$usec;
496 $elapsed = $now - $start;
497
498 # Use real server name if available, so we know which machine
499 # in a server farm generated the current page.
500 if ( function_exists( 'posix_uname' ) ) {
501 $uname = @posix_uname();
502 } else {
503 $uname = false;
504 }
505 if( is_array( $uname ) && isset( $uname['nodename'] ) ) {
506 $hostname = $uname['nodename'];
507 } else {
508 # This may be a virtual server.
509 $hostname = $_SERVER['SERVER_NAME'];
510 }
511 $com = sprintf( "<!-- Served by %s in %01.2f secs. -->",
512 $hostname, $elapsed );
513 return $com;
514 }
515
516 /**
517 * Note: these arguments are keys into wfMsg(), not text!
518 */
519 function errorpage( $title, $msg ) {
520 global $wgTitle;
521
522 $this->mDebugtext .= 'Original title: ' .
523 $wgTitle->getPrefixedText() . "\n";
524 $this->setPageTitle( wfMsg( $title ) );
525 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
526 $this->setRobotpolicy( 'noindex,nofollow' );
527 $this->setArticleRelated( false );
528 $this->suppressQuickbar();
529
530 $this->enableClientCache( false );
531 $this->mRedirect = '';
532
533 $this->mBodytext = '';
534 $this->addHTML( '<p>' . wfMsg( $msg ) . "</p>\n" );
535 $this->returnToMain( false );
536
537 $this->output();
538 wfErrorExit();
539 }
540
541 function sysopRequired() {
542 global $wgUser;
543
544 $this->setPageTitle( wfMsg( 'sysoptitle' ) );
545 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
546 $this->setRobotpolicy( 'noindex,nofollow' );
547 $this->setArticleRelated( false );
548 $this->mBodytext = '';
549
550 $sk = $wgUser->getSkin();
551 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
552 $this->addHTML( wfMsg( 'sysoptext', $ap ) );
553 $this->returnToMain();
554 }
555
556 function developerRequired() {
557 global $wgUser;
558
559 $this->setPageTitle( wfMsg( 'developertitle' ) );
560 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
561 $this->setRobotpolicy( 'noindex,nofollow' );
562 $this->setArticleRelated( false );
563 $this->mBodytext = '';
564
565 $sk = $wgUser->getSkin();
566 $ap = $sk->makeKnownLink( wfMsgForContent( 'administrators' ), '' );
567 $this->addHTML( wfMsg( 'developertext', $ap ) );
568 $this->returnToMain();
569 }
570
571 function loginToUse() {
572 global $wgUser, $wgTitle, $wgContLang;
573
574 $this->setPageTitle( wfMsg( 'loginreqtitle' ) );
575 $this->setHTMLTitle( wfMsg( 'errorpagetitle' ) );
576 $this->setRobotpolicy( 'noindex,nofollow' );
577 $this->setArticleFlag( false );
578 $this->mBodytext = '';
579 $this->addWikiText( wfMsg( 'loginreqtext' ) );
580
581 # We put a comment in the .html file so a Sysop can diagnose the page the
582 # user can't see.
583 $this->addHTML( "\n<!--" .
584 $wgContLang->getNsText( $wgTitle->getNamespace() ) .
585 ':' .
586 $wgTitle->getDBkey() . '-->' );
587 $this->returnToMain(); # Flip back to the main page after 10 seconds.
588 }
589
590 function databaseError( $fname, $sql, $error, $errno ) {
591 global $wgUser, $wgCommandLineMode;
592
593 $this->setPageTitle( wfMsgNoDB( 'databaseerror' ) );
594 $this->setRobotpolicy( 'noindex,nofollow' );
595 $this->setArticleRelated( false );
596 $this->enableClientCache( false );
597 $this->mRedirect = '';
598
599 if ( $wgCommandLineMode ) {
600 $msg = wfMsgNoDB( 'dberrortextcl', htmlspecialchars( $sql ),
601 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
602 } else {
603 $msg = wfMsgNoDB( 'dberrortext', htmlspecialchars( $sql ),
604 htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
605 }
606
607 if ( $wgCommandLineMode || !is_object( $wgUser )) {
608 print $msg."\n";
609 wfErrorExit();
610 }
611 $this->mBodytext = $msg;
612 $this->output();
613 wfErrorExit();
614 }
615
616 function readOnlyPage( $source = null, $protected = false ) {
617 global $wgUser, $wgReadOnlyFile;
618
619 $this->setRobotpolicy( 'noindex,nofollow' );
620 $this->setArticleRelated( false );
621
622 if( $protected ) {
623 $this->setPageTitle( wfMsg( 'viewsource' ) );
624 $this->addWikiText( wfMsg( 'protectedtext' ) );
625 } else {
626 $this->setPageTitle( wfMsg( 'readonly' ) );
627 $reason = file_get_contents( $wgReadOnlyFile );
628 $this->addWikiText( wfMsg( 'readonlytext', $reason ) );
629 }
630
631 if( is_string( $source ) ) {
632 if( strcmp( $source, '' ) == 0 ) {
633 $source = wfMsg( 'noarticletext' );
634 }
635 $rows = $wgUser->getOption( 'rows' );
636 $cols = $wgUser->getOption( 'cols' );
637 $text = "\n<textarea cols='$cols' rows='$rows' readonly='readonly'>" .
638 htmlspecialchars( $source ) . "\n</textarea>";
639 $this->addHTML( $text );
640 }
641
642 $this->returnToMain( false );
643 }
644
645 function fatalError( $message ) {
646 $this->setPageTitle( wfMsg( "internalerror" ) );
647 $this->setRobotpolicy( "noindex,nofollow" );
648 $this->setArticleRelated( false );
649 $this->enableClientCache( false );
650 $this->mRedirect = '';
651
652 $this->mBodytext = $message;
653 $this->output();
654 wfErrorExit();
655 }
656
657 function unexpectedValueError( $name, $val ) {
658 $this->fatalError( wfMsg( 'unexpected', $name, $val ) );
659 }
660
661 function fileCopyError( $old, $new ) {
662 $this->fatalError( wfMsg( 'filecopyerror', $old, $new ) );
663 }
664
665 function fileRenameError( $old, $new ) {
666 $this->fatalError( wfMsg( 'filerenameerror', $old, $new ) );
667 }
668
669 function fileDeleteError( $name ) {
670 $this->fatalError( wfMsg( 'filedeleteerror', $name ) );
671 }
672
673 function fileNotFoundError( $name ) {
674 $this->fatalError( wfMsg( 'filenotfound', $name ) );
675 }
676
677 /**
678 * return from error messages or notes
679 * @param $auto automatically redirect the user after 10 seconds
680 * @param $returnto page title to return to. Default is Main Page.
681 */
682 function returnToMain( $auto = true, $returnto = NULL ) {
683 global $wgUser, $wgOut, $wgRequest;
684
685 if ( $returnto == NULL ) {
686 $returnto = $wgRequest->getText( 'returnto' );
687 }
688 $returnto = htmlspecialchars( $returnto );
689
690 $sk = $wgUser->getSkin();
691 if ( '' == $returnto ) {
692 $returnto = wfMsgForContent( 'mainpage' );
693 }
694 $link = $sk->makeKnownLink( $returnto, '' );
695
696 $r = wfMsg( 'returnto', $link );
697 if ( $auto ) {
698 $titleObj = Title::newFromText( $returnto );
699 $wgOut->addMeta( 'http:Refresh', '10;url=' . $titleObj->escapeFullURL() );
700 }
701 $wgOut->addHTML( "\n<p>$r</p>\n" );
702 }
703
704 /**
705 * This function takes the existing and broken links for the page
706 * and uses the first 10 of them for META keywords
707 */
708 function addMetaTags () {
709 global $wgLinkCache , $wgOut ;
710 $good = array_keys ( $wgLinkCache->mGoodLinks ) ;
711 $bad = array_keys ( $wgLinkCache->mBadLinks ) ;
712 $a = array_merge ( $good , $bad ) ;
713 $a = array_slice ( $a , 0 , 10 ) ; # 10 keywords max
714 $a = implode ( ',' , $a ) ;
715 $strip = array(
716 "/<.*?" . ">/" => '',
717 "/[_]/" => ' '
718 );
719 $a = htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),$a ));
720
721 $wgOut->addMeta ( 'KEYWORDS' , $a ) ;
722 }
723
724 /**
725 * @private
726 */
727 function headElement() {
728 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
729 global $wgUser, $wgContLang, $wgRequest;
730
731 $xml = ($wgMimeType == 'text/xml');
732 if( $xml ) {
733 $ret = "<" . "?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?" . ">\n";
734 } else {
735 $ret = '';
736 }
737
738 $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
739
740 if ( "" == $this->mHTMLtitle ) {
741 $this->mHTMLtitle = wfMsg( "pagetitle", $this->mPagetitle );
742 }
743 if( $xml ) {
744 $xmlbits = "xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\"";
745 } else {
746 $xmlbits = '';
747 }
748 $rtl = $wgContLang->isRTL() ? " dir='RTL'" : '';
749 $ret .= "<html $xmlbits lang=\"$wgContLanguageCode\" $rtl>\n";
750 $ret .= "<head>\n<title>" . htmlspecialchars( $this->mHTMLtitle ) . "</title>\n";
751 array_push( $this->mMetatags, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
752
753 $ret .= $this->getHeadLinks();
754 global $wgStylePath;
755 if( $this->isPrintable() ) {
756 $media = '';
757 } else {
758 $media = "media='print'";
759 }
760 $printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css" );
761 $ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
762
763 $sk = $wgUser->getSkin();
764 $ret .= $sk->getHeadScripts();
765 $ret .= $this->mScripts;
766 $ret .= $sk->getUserStyles();
767
768 $ret .= "</head>\n";
769 return $ret;
770 }
771
772 function getHeadLinks() {
773 global $wgRequest, $wgStylePath;
774 $ret = '';
775 foreach ( $this->mMetatags as $tag ) {
776 if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
777 $a = 'http-equiv';
778 $tag[0] = substr( $tag[0], 5 );
779 } else {
780 $a = 'name';
781 }
782 $ret .= "<meta $a=\"{$tag[0]}\" content=\"{$tag[1]}\" />\n";
783 }
784 $p = $this->mRobotpolicy;
785 if ( '' == $p ) { $p = 'index,follow'; }
786 $ret .= "<meta name=\"robots\" content=\"$p\" />\n";
787
788 if ( count( $this->mKeywords ) > 0 ) {
789 $strip = array(
790 "/<.*?" . ">/" => '',
791 "/[_]/" => ' '
792 );
793 $ret .= "<meta name=\"keywords\" content=\"" .
794 htmlspecialchars(preg_replace(array_keys($strip), array_values($strip),implode( ",", $this->mKeywords ))) . "\" />\n";
795 }
796 foreach ( $this->mLinktags as $tag ) {
797 $ret .= '<link';
798 foreach( $tag as $attr => $val ) {
799 $ret .= " $attr=\"" . htmlspecialchars( $val ) . "\"";
800 }
801 $ret .= " />\n";
802 }
803 if( $this->isSyndicated() ) {
804 # FIXME: centralize the mime-type and name information in Feed.php
805 $link = $wgRequest->escapeAppendQuery( 'feed=rss' );
806 $ret .= "<link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='$link' />\n";
807 $link = $wgRequest->escapeAppendQuery( 'feed=atom' );
808 $ret .= "<link rel='alternate' type='application/rss+atom' title='Atom 0.3' href='$link' />\n";
809 }
810 # FIXME: get these working
811 # $fix = htmlspecialchars( $wgStylePath . "/ie-png-fix.js" );
812 # $ret .= "<!--[if gte IE 5.5000]><script type='text/javascript' src='$fix'>< /script><![endif]-->";
813 return $ret;
814 }
815
816 /**
817 * Run any necessary pre-output transformations on the buffer text
818 */
819 function transformBuffer( $options = 0 ) {
820 }
821
822 }
823
824 }
825
826 ?>